# -*- shell-script -*-

# 31bus-device-tree - Create VPD directories for buses in device-tree.

# This file is part of the Linux lsvpd package.

# (C) Copyright IBM Corp. 2004, 2005

# Maintained by Martin Schwenke <martins@au.ibm.com>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
# $Id: 31bus_device_tree,v 1.1 2006/04/11 18:38:28 emunson Exp $

[ -n "$source_device_tree" ] || return 0

######################################################################

list_buses ()
{
    # Sets: bus_list
    bus_list=""

    local types="pci isa"
    local t
    for t in $types ; do
	list_buses_of_type "$t"
    done
}

list_buses_of_type ()
{
    local type="$1"

    local b
    for b in $(find "${db_bus_dt_dir}" -type d -name "${type}@*" | sort) ; do
	bus_list="${bus_list} ${type}@${b}"
    done
}

add_bus ()
{
    local type="$1"
    local node="$2"

    local ds
    case "$type" in
	(pci) ds="PCI Bus" ;;
	(isa) ds="ISA Bus" ;;
    esac

    local yl
    get_yl "bus" "unknown" "unknown" \
	"${source_device_tree}${node#${db_bus_dt_dir}}" "unknown"

    local mf tm sn cd rl rm

    vpd_create_hook "$node"

    local vpd_dir fc
    vpd_dir_set_hook "$node"
    do_fc_hook "$node"
    vpd_field_ensure "$vpd_dir" "FC" "$fc"
}
